#include <iostream>
#include <cstdio>
#include <algorithm>
#define int long long
#define maxint 2147483647
#define N 100003
#define file
using namespace std;
int t, n, m, l, v, mxp = -1, ans1, ans2, cnt0;
int d[N], s[N], a[N], p[N], sta[N];
double bev[N], be0[N];
signed main()
{
#ifdef file
    freopen("detect.in", "r", stdin);
    freopen("detect.out", "w", stdout);
#endif
    cin >> t;
    while (t--)
    {
        cin >> n >> m >> l >> v;
        for (int i = 1; i <= n; i++)
            cin >> d[i] >> s[i] >> a[i];
        ans1 = 0, ans2 = 0, cnt0 = 0, mxp = 0;
        for (int i = 1; i <= m; i++)
        {
            cin >> p[i];
            if (p[i] > mxp)
                mxp = p[i];
        }
        for (int i = 0; i < 100003; i++)
            bev[i] = maxint, be0[i] = maxint, sta[i] = 0;
        for (int i = 1; i <= n; i++)
        {
            if (a[i] == 0)
            {
                cnt0++;
                if (s[i] > v && d[i] <= mxp)
                {
                    ans1++;
                    sta[lower_bound(p + 1, p + m + 1, d[i]) - p]++;
                }
            }
            else
            {
                bev[i] = d[i] + 1.0 * (v * v - s[i] * s[i]) / (2 * a[i]);
                //cout << bev[i] << endl;
                if (a[i] < 0)
                {
                    be0[i] = d[i] + 1.0 * (0 - s[i] * s[i]) / (2 * a[i]);
                    //cout << be0[i] << endl;
                }
                if (a[i] > 0)
                {
                    if (mxp > bev[i])
                    {
                        ans1++;
                        sta[upper_bound(p + 1, p + m + 1, bev[i]) - p]++;
                    }
                }
                else if (a[i] < 0)
                {
                    int c1 = lower_bound(p + 1, p + m + 1, d[i]) - p - 1;
                    int c2 = lower_bound(p + 1, p + m + 1, bev[i]) - p;
                    if (c2 - c1 > 1)
                    {
                        ans1++;
                        sta[c1 + 1]++;
                    }
                }
            }
        }
        cout << ans1 << ' ';
        for (int i = 1; i <= n; i++)
            if (!sta[i])
                ans2++;
        if (!ans1)
            cout << m << endl;
        else
        {
            if (cnt0 == n)
                cout << m - 1 << endl;
            else
                cout << ans2 << endl;
        }
    }
    return 0;
}
